/**
 * Created by zyh on 2019/4/18.
 */

import Utils from './mod.utils';
import String from './mod.string';
import db from '../mod/db';
import Util from './util.js';

import Log from '../mod/log'
let log = new Log('local.db')


let dbData = {}
let name = 'local'
let tables = {
  user: {
    name: 'user',
  },
}
const ids = {
  userObj: 'userObj',
}
let DB = {
  getUsersObj: function () {
    var userObj = dbData.userObj || {};
    return userObj;
  },
  setUsersObj: function (data = {}) {
    dbData.userObj = data;
  },
  getUsername: function (userid) {
    var UsersObj = dbData.userObj || {};
    var name = userid;
    if (UsersObj[userid] && UsersObj[userid].name != '') {
      name = UsersObj[userid].name;
    }
    return name;
  },
  getUserNoforid: function (userid) {
    var UsersObj = dbData.userObj || {};
    var no = userid;
    for (var k in UsersObj) {
      if (!UsersObj[k]) {
        continue;
      }
      var id = UsersObj[k].id;
      var no1 = UsersObj[k].no;
      if (id == userid) {
        no = no1;
        break;
      }
    }
    return no;
  },
  getUserImg: function (userid) {
    var UsersObj = dbData.userObj || {};
    var image = '';
    if (UsersObj[userid] && UsersObj[userid].image != '') {
      image = UsersObj[userid].image;
    }
    return image;
  },
  getNoToId: function (no) {
    var UsersObj = dbData.userObj || {};
    var id = '';
    if (UsersObj[no] && UsersObj[no].id != '') {
      id = UsersObj[no].id;
    }
    return id;
  },
}
export default DB
